<?php
/**
 * Each engineer has a duty to keep the code elegant
 * Created by wolffy.
 * Author @wolffy<13750088090@sina.cn>
 * Date: 2018/8/12
 * Time: 11:40
 */
namespace App\Repositories;

use App\Models\BankSupport;
use App\Models\UserLevelPassageBank;

class UserLevelPassageBankRepository
{
    /**
     * 根据id获取还款账单资料
     * @param $id
     * @return mixed
     */
    public function byId($id)
    {
        return UserLevelPassageBank::find($id);
    }

    public function first($userLevelId, $bankSupportId)
    {
        return UserLevelPassageBank::where([
            'level_id' => $userLevelId,
            'bank_support_id' => $bankSupportId,
        ])->first();
    }

    public function passageToBank($passageId, $bankCode, $levelId)
    {
        $bankSupport = BankSupport::where([
            'passage_id' => $passageId,
            'bank_code' => $bankCode,
        ])->first();
        return $this->first($levelId, $bankSupport->id);
    }
}